home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4915 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: time as a seed
  5. Date: 7 Feb 1996 14:31:12 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4fb97gINNbbu@keats.ugrad.cs.ubc.ca>
  8. References: <310EEB1E.688A@one.ucdavis.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <310EEB1E.688A@one.ucdavis.edu>,
  12. Gary Huxel  <huxel@one.ucdavis.edu> wrote:
  13. >I need help with what should be a simple programming problem.  I am
  14. >trying to use time since UTC as a seed for a simulation using Cellular
  15. >by Dana Eckert.  I am doing this on a SUN with Solaris 2.3 using GNU
  16. >libraries.  I have tried the Standard C library approach and the normal
  17. >GNU method, but these do not seem to work.  Any suggestions/
  18.  
  19. For your purposes, it might be sufficient to do srand(getpid() * time(NULL)).
  20. You want to include the process ID of your program in the seed, otherwise
  21. multiple executions of the program launched within the same second of time will
  22. have identical sequences.
  23.  
  24. Not that 32-bit seeds are not cryptographically strong, since they give you
  25. only 2^32 possible sequences---hence if you generate, say, random keys, you
  26. effectively reduce the space to 2^32. In your simulation this is probably not a
  27. concern.
  28. -- 
  29.  
  30.